package com.each_time_data.service.impl;

import com.each_time_data.pojo.BasePageVo;
import org.apache.http.HttpEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;

import java.io.IOException;
import java.util.ArrayList;

/**
 * @author Administrator
 */
@Service
public class UrlService  {

    //获取首页每行的链接信息
    public static String getDataURL() throws IOException {
        ArrayList<BasePageVo> resultList = new ArrayList<>();
        // String url = "http://live.win007.com/";
        CloseableHttpClient httpClient = HttpClients.createDefault();
        // 创建httpClient实例
        HttpGet httpGet = new HttpGet("http://live.win007.com/vbsxml/goalBf3.xml?r=007" + System.currentTimeMillis());
        // 创建httpget实例
        httpGet.setHeader("User-Agent", "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36");
        // 设置请求头消息User-Agent
        httpGet.addHeader("Referer", "http://live.win007.com/");
        CloseableHttpResponse response = httpClient.execute(httpGet);
        // 执行http get请求
        HttpEntity entity = response.getEntity();
        // 获取返回实体
        String str = EntityUtils.toString(entity, "utf-8");
        // 获取网页内容
        int index01 = str.indexOf("<ids>");
        int index02 = str.indexOf("</ids>");
        String substring = str.substring(index01+5, index02-1 );
        String[] ids = substring.split(",");
        return substring;
    }

}
